<template xmlns="http://www.w3.org/1999/html">
  <view class="Mall4j con">
    <view v-if="uniLoginLogoImg" class="logo">
      <image :src="uniLoginLogoImg" mode="heightFix" />
    </view>
    <!-- 登录 -->
    <!--		<view v-if="!isForgetPassword && !isCancellation" class="login-form">-->
    <view v-if="!isForgetPassword && !isCancellation" class="login-page">
      <view class="form-title">{{ i18n.login }}</view>
      <!--			<view :class="['item',errorTips==1? 'error':'']">-->
      <!--				<view class="account">-->
      <!--					<text class="input-item">{{ i18n.username }}</text>-->
      <!--					<input type="text" data-type="account" placeholder-class="inp-palcehoder"-->
      <!--						:placeholder="i18n.enterUsername" @confirm="login" @input="getInputVal"></input>-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==1" class="error-text"><text class="warning-icon">!</text>{{ i18n.usernameWarn }}-->
      <!--				</view>-->
      <!--			</view>-->
      <!--			<view :class="['item',errorTips==2? 'error':'']">-->
      <!--				<view class="account">-->
      <!--					<text class="input-item">{{ i18n.password }}</text>-->
      <!--					<input v-model="credentials" type="password" data-type="password" placeholder-class="inp-palcehoder"-->
      <!--						:placeholder="i18n.password" @confirm="login" @input="getInputVal"></input>-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==2" class="error-text"><text class="warning-icon">!</text>{{ i18n.enterPassword }}-->
      <!--				</view>-->
      <!--			</view>-->
      <!--			<view class="item statement">-->
      <!--				<view class="statement-text">-->
      <!--					<label @tap.stop="handlePrivacyClick">-->
      <!--						<checkbox class="check-box" :checked="isPrivacy===1" />-->
      <!--						{{ i18n.haveReadAndAppgree }}-->
      <!--						<text @tap.stop="toService()">《{{ i18n.termsOfService }}》</text>-->
      <!--						<text style="color:#000">{{ i18n.and }}</text>-->
      <!--						<text @tap.stop="toPrivacy()">《{{ i18n.privacyPolicy }}》</text>-->
      <!--					</label>-->
      <!--				</view>-->
      <!--			</view>-->
      <!--			<view class="operate">-->
      <!--				<view class="forgot-password" @tap="forgotPassword">{{ i18n.changePassword }}></view>-->
      <!--				<view class="to-register" @tap="toRegitser">-->
      <!--					{{ i18n.notUsername }}<text>{{ i18n.registeredUsername }}></text>-->
      <!--				</view>-->
      <!--			</view>-->

      <form>
        <uni-forms class="form-items" ref="loginForm" :modelValue="loginData" :rules="loginRules">
          <uni-forms-item class="input-items" label="手机号" name="principal" required>
            <input type="text" class="form-input" v-model="loginData.principal" placeholder="请输入手机号" />
          </uni-forms-item>
          <uni-forms-item class="input-items" label="密码" name="password" required>
            <input type="password" class="form-input" v-model="loginData.password" placeholder="请输入密码" />
          </uni-forms-item>
        </uni-forms>
      </form>
      <view class="item statement">
        <view class="statement-text">
          <label @tap.stop="handlePrivacyClick">
            <checkbox class="check-box" :checked="isPrivacy===1" />
            {{ i18n.haveReadAndAppgree }}
            <text class="statement-text_1" @tap.stop="toService">《{{ i18n.termsOfService }}》</text>
            <text style="color:#000">{{ i18n.and }}</text>
            <text class="statement-text_1" @tap.stop="toPrivacy">《{{ i18n.privacyPolicy }}》</text>
          </label>
        </view>
      </view>
      <view class="operate other-opration">
        <view class="forgot-password statement-text_1" @tap="forgotPassword">{{ i18n.changePassword }}></view>
        <view class="to-register statement-text_1" @tap="toRegitser">
          {{ i18n.notUsername }}
          <text>{{ i18n.registeredUsername }}></text>
        </view>
      </view>
      <view class="text-wrapper_5 flex-col" @tap="loginSubmit">
        <text class="text_11">登录</text>
      </view>
      <view class="text-wrapper_back flex-col" @tap="toIndex">
        <text class="text_11">返回首页</text>
      </view>

    </view>

    <!-- 修改密码 -->
    <!--		<view v-if="isForgetPassword" class="login-form">-->
    <view v-if="isForgetPassword" class="change-password-page">
      <view class="form-title">{{ i18n.changePassword }}</view>
      <!--			<view :class="['item',errorTips ? 'error':'']">-->
      <!--				<view class="account">-->
      <!--					<text class="input-item">{{ i18n.phoneNumber }}</text>-->
      <!--					<input v-model="principal" type="text" data-type="account" placeholder-class="inp-palcehoder"-->
      <!--						:placeholder="i18n.enterPhone" maxlength="11" @input="getInputVal"></input>-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==1" class="error-text"><text class="warning-icon">!</text>{{ i18n.phoneWarn }}-->
      <!--				</view>-->
      <!--				<view v-if="!principal && errorTips==8" class="error-text"><text-->
      <!--						class="warning-icon">!</text>{{ i18n.enterPhone }}</view>-->
      <!--			</view>-->
      <!--			&lt;!&ndash; 验证码 &ndash;&gt;-->
      <!--			<view :class="['item',errorTips ? 'error':'']">-->
      <!--				<view class="account">-->
      <!--					<text class="input-item">{{ i18n.verificationCode }}</text>-->
      <!--					<input v-model="validCode" type="text" class="int-yzm" placeholder-class="inp-palcehoder"-->
      <!--						:placeholder="i18n.enterCode"></input>-->
      <!--					<text v-if="show" class="input-btn" @tap="getCode">{{ i18n.getCode }}</text>-->
      <!--					<text v-if="!show" class="input-btn">{{ count }} s</text>-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==3" class="error-text"><text class="warning-icon">!</text>{{ i18n.enterCode }}-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==6" class="error-text"><text-->
      <!--						class="warning-icon">!</text>{{ i18n.enterCodeFirst }}</view>-->
      <!--			</view>-->
      <!--			&lt;!&ndash; 新密码 &ndash;&gt;-->
      <!--			<view :class="['item',errorTips ? 'error':'']">-->
      <!--				<view class="account">-->
      <!--					<text class="input-item">{{ i18n.newPassword }}</text>-->
      <!--					<input type="password" data-type="0" :value="newPassWord" placeholder-class="inp-palcehoder"-->
      <!--						:placeholder="i18n.enterNew" @input="getPassInputVal"></input>-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==4" class="error-text"><text class="warning-icon">!</text>{{ i18n.enterNew }}-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==9" class="error-text"><text-->
      <!--						class="warning-icon">!</text>{{ i18n.passwordVerification }}</view>-->
      <!--				<view v-if="errorTips==10" class="error-text"><text-->
      <!--						class="warning-icon">!</text>{{ i18n.enterNewPasswordTips }}</view>-->
      <!--			</view>-->
      <!--			&lt;!&ndash; 新密码 &ndash;&gt;-->
      <!--			<view :class="['item',errorTips ? 'error':'']">-->
      <!--				<view class="account">-->
      <!--					<text class="input-item">{{ i18n.confirmNew }}</text>-->
      <!--					<input type="password" data-type="1" :value="comNewPassWord" placeholder-class="inp-palcehoder"-->
      <!--						:placeholder="i18n.enterNewAgain" @input="getPassInputVal"></input>-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==5" class="error-text"><text class="warning-icon">!</text>{{ i18n.enterNewAgain }}-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==7 && !identical" class="error-text"><text-->
      <!--						class="warning-icon">!</text>{{ i18n.comparedPassword }}</view>-->
      <!--			</view>-->
      <form>
        <uni-forms class="form-items" ref="changePasswordForm" :modelValue="changePasswordData" :rules="changePasswordRules">
          <uni-forms-item class="input-items" label="手机号" name="principal" required>
            <!--          <text class="form-input-text" > {{ "手机号 " }} </text>-->
            <input type="text" class="form-input" v-model="changePasswordData.principal" placeholder="手机号" />
          </uni-forms-item>
          <uni-forms-item class="input-items" label="验证码" name="validCode" required>
            <input type="text" class="form-input" v-model="changePasswordData.validCode" placeholder="验证码" />
            <view class="codeBtn1" v-if="show" @tap="getCode(changePasswordData.principal)">获取验证码</view>
            <view class="codeBtn1" v-else>{{ count }}</view>
          </uni-forms-item>
          <uni-forms-item class="input-items" label="新密码" name="newPassWord" required>
            <input type="password" class="form-input" v-model="changePasswordData.newPassWord" placeholder="新密码" />
          </uni-forms-item>
          <uni-forms-item class="input-items" label="确认密码" name="comNewPassWord" required>
            <input type="password" class="form-input" v-model="changePasswordData.comNewPassWord" placeholder="确认新密码" />
          </uni-forms-item>
        </uni-forms>
      </form>
      <view class="text-wrapper_5 flex-col" @click="changePasswordSubmit">
        <text class="text_11">确认修改</text>
      </view>
      <view class="text-wrapper_back flex-col" v-if="!isPersonalCenter" @tap="toIndex">
        <text class="text_11">返回首页</text>
      </view>
    </view>
    <!--		<view v-if="!isForgetPassword && !isCancellation">-->
    <!--			<button class="authorized-btn" @tap="login">{{ i18n.login }}</button>-->
    <!--			<button class="to-idx-btn" @tap="toIndex">{{ i18n.backHomepage }}</button>-->
    <!--		</view>-->
    <!--		<view v-if="isForgetPassword">-->
    <!--			<button class="authorized-btn" @tap="checkValidCode">{{ i18n.confirmChanges }}</button>-->
    <!--			<button v-if="!isPersonalCenter" class="to-idx-btn" @tap="goBack">{{ i18n.BackLogin }}</button>-->
    <!--		</view>-->

    <!-- 账号注销 -->
    <view v-if="isCancellation" class="cancellation-page">
      <view class="form-title">{{ "注销账户" }}</view>
      <!-- 验证码 -->
      <!--			<view :class="['item',errorTips ? 'error':'']">-->
      <!--				<view class="account">-->
      <!--					<text class="input-item">{{ i18n.verificationCode }}</text>-->
      <!--					<input v-model="validCode" type="text" class="int-yzm" placeholder-class="inp-palcehoder"-->
      <!--						:placeholder="i18n.enterCode"></input>-->
      <!--					<text v-if="show" class="input-btn" @tap="getCode">{{ i18n.getCode }}</text>-->
      <!--					<text v-if="!show" class="input-btn">{{ count }} s</text>-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==3" class="error-text"><text class="warning-icon">!</text>{{ i18n.enterCode }}-->
      <!--				</view>-->
      <!--				<view v-if="errorTips==6" class="error-text"><text-->
      <!--						class="warning-icon">!</text>{{ i18n.enterCodeFirst }}</view>-->
      <!--			</view>-->

      <!--			<view class="cancellation-btn">-->
      <!--				<button class="cancellation-btn-confirm" @tap="checkValidCode">确认</button>-->
      <!--			</view>-->
      <form>
        <uni-forms class="form-items" ref="cancellationForm" :modelValue="cancellationData" :rules="cancellationRules">
          <uni-forms-item class="input-items" label="验证码" name="validCode" required>
            <input type="text" class="form-input" v-model="cancellationData.validCode" placeholder="验证码" />
            <button class="codeBtn1" v-if="show" @tap="getCode">获取验证码</button>
            <button class="codeBtn2" v-else>{{ count }}</button>
          </uni-forms-item>
        </uni-forms>
      </form>
      <view class="text-wrapper_5 flex-col" @click="cancellationSubmit">
        <text class="text_11">确认</text>
      </view>
    </view>

    <privacy-pop v-if="showPop" @hidePop="hidePop" @confirm="popConfirm" />
  </view>
</template>

<script>
import { createLogger } from "vuex";

var http = require('../../utils/http')
var util = require('../../utils/util.js')
import {
  encrypt
} from '@/utils/crypto.js'
import privacyPop from '../../components/privacy-pop/index.vue'

export default {

  components: {
    privacyPop
  },
  props: {},
  data () {
    return {
      principal: '', // 账号
      credentials: '', // 密码
      isForgetPassword: false, // 是否修改密码
      isPersonalCenter: false, // 是否从个人中心页面跳转过来
      show: true, // 获取验证码按钮

      isCancellation: false, // 是否注销账号
      userInfo: {},
      isSuccessCancellation: false, // 注销账号的验证码是否正确

      // 验证码相关
      validCode: '', // 验证码
      count: '',
      timer: null,
      hadGotCode: false, // 是否已点击获取验证码

      newPassWord: '', // 新密码
      comNewPassWord: '', // 确认新密码

      checkRegisterSmsFlag: '', // 校验验证码成功的标识
      errorTips: 0, // 错误提示
      identical: Boolean, // 是否一致
      uniLoginLogoImg: uni.getStorageSync('uniLoginLogoImg'), // Logo
      isWx: false,
      isPrivacy: uni.getStorageSync('isPrivacy') || 0,
      showPop: false,
      changePasswordData: {
        principal: '',
        validCode: '',
        newPassWord: '',
        comNewPassWord: ''
      },
      loginData: {
        principal: '',
        password: ''
      },
      cancellationData: {
        validCode: ''
      },
      changePasswordRules: {
        principal: {
          rules: [
            {
              required: true,
              errorMessage: '请输入手机号',
              trigger: ['change', 'blur']
            },
            {
              minLength: 11,
              maxLength: 11,
              errorMessage: '长度为11位',
              trigger: ['change', 'blur']
            },
            {
              validateFunction: function (rule, value, data, callback) {
                let iphoneReg = /^1[0-9]{10}$/
                if (!iphoneReg.test(value)) {
                  callback('格式不正确')
                }
                return true
              }
            }
          ]
        },
        validCode: {
          rules: [
            {
              required: true,
              errorMessage: '请输入验证码',
              trigger: ['change', 'blur']
            },
            {
              minLength: 6,
              maxLength: 6,
              errorMessage: '长度为6位',
              trigger: ['change', 'blur']
            }
          ]
        },
        newPassWord: {
          rules: [
            {
              required: true,
              errorMessage: '请输入新密码',
              trigger: ['change', 'blur']
            },
            {
              minLength: 6,
              maxLength: 16,
              errorMessage: '长度为6~16位',
              trigger: ['change', 'blur']
            }
          ]
        },
        comNewPassWord: {
          rules: [
            {
              required: true,
              errorMessage: '请再次输入新密码',
              trigger: ['change', 'blur']
            },
            {
              validateFunction: (rule, value, data, callback) => {
                if (this.changePasswordData.newPassWord !== this.changePasswordData.comNewPassWord) {
                  callback('两次密码不一致')
                }
                return true
              }
            }
          ]
        }
      },
      loginRules: {
        principal: {
          rules: [
            {
              required: true,
              errorMessage: '请输入手机号',
              trigger: ['change', 'blur']
            },
            {
              minLength: 11,
              maxLength: 11,
              errorMessage: '长度为11位',
              trigger: ['change', 'blur']
            },
            {
              validateFunction: function (rule, value, data, callback) {
                let iphoneReg = /^1[0-9]{10}$/
                if (!iphoneReg.test(value)) {
                  callback('格式不正确')
                }
                return true
              }
            },
          ]
        },
        password: {
          rules: [
            {
              required: true,
              errorMessage: '请输入密码',
              trigger: ['change', 'blur']
            }
            // {
            //   minLength : 6,
            //   maxLength : 16,
            //   errorMessage: '长度为6~16位',
            //   trigger: ['change','blur']
            // }
          ]
        },
      },
      cancellationRules: {
        validCode: {
          rules: [
            {
              required: true,
              errorMessage: '请输入验证码',
              trigger: ['change', 'blur']
            },
            {
              minLength: 6,
              maxLength: 6,
              errorMessage: '长度为6位',
              trigger: ['change', 'blur']
            }
          ]
        },
      }
    }
  },

  computed: {
    i18n () {
      return this.$t('index')
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.isForgetPassword) {
      this.isForgetPassword = options.isForgetPassword
      uni.setNavigationBarTitle({
        title: this.i18n.changePassword
      })
    } else {
      util.weChatLogin()
    }
    if (options.isPersonalCenter) {
      this.isPersonalCenter = options.isPersonalCenter

      uni.setNavigationBarTitle({
        title: this.i18n.changePassword
      })
    }
    if (options.isCancellation) {
      this.isCancellation = options.isCancellation
      var params = {
        url: '/p/user/userInfo',
        method: 'GET',
        data: {},
        dontTrunLogin: true,
        callBack: (res) => {
          this.userInfo = res
        }
      }
      http.request(params)
    } else {
      // 头部导航标题
      // uni.setNavigationBarTitle({
      // 	// title: this.i18n.userLogin
      // 	title: "身份验证"
      // })
      if (!this.isForgetPassword && !this.isCancellation) {
        // login
        uni.setNavigationBarTitle({
          title: this.i18n.userLogin
        })
      } else if (this.isForgetPassword) {
        // changepassword
        uni.setNavigationBarTitle({
          title: this.i18n.changePassword
        })
      } else {
        // shuxiao
        uni.setNavigationBarTitle({
          title: "账号注销"
        })
      }
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  },
  watch: {
    principal (nv, ov) {
      this.errorTips = 0
    }
  },

  methods: {

    /**
     * 弹窗确认
     */
    popConfirm (val) {
      this.isPrivacy = val
      this.showPop = false
      this.login()
    },
    /**
     * 弹窗取消
     */
    hidePop () {
      this.showPop = false
    },
    /**
     * 条款点击事件(勾选/取选)
     */
    handlePrivacyClick () {
      this.isPrivacy = this.isPrivacy === 1 ? 0 : 1
    },
    changePasswordSubmit () {
      this.$refs.changePasswordForm.validate().then(res => {
        this.principal = this.changePasswordData.principal
        this.validCode = this.changePasswordData.validCode
        this.newPassWord = this.changePasswordData.newPassWord
        this.comNewPassWord = this.changePasswordData.comNewPassWord
        console.log(this.changePasswordData.principal, this.principal)
        console.log(this.changePasswordData.validCode, this.validCode)
        console.log(this.changePasswordData.newPassWord, this.newPassWord)
        console.log(this.changePasswordData.comNewPassWord, this.comNewPassWord)
        this.checkValidCode()
      }).catch(err => {
        uni.showToast({
          title: "数据错误,请重试",
          icon: 'none',
          duration: 1500
        })
      })
    },
    loginSubmit () {
      this.$refs.loginForm.validate().then(res => {
        this.principal = this.loginData.principal
        this.credentials = this.loginData.password
        this.login()
      }).catch(err => {
        uni.showToast({
          title: "数据错误,请重试",
          icon: 'none',
          duration: 1500
        })
      })
    },
    cancellationSubmit () {
      this.$refs.cancellationForm.validate().then(res => {
        this.validCode = this.cancellationData.validCode
        this.principal = this.userInfo.userMobile
        this.checkValidCode()
      }).catch(err => {
        uni.showToast({
          title: "数据错误,请重试",
          icon: 'none',
          duration: 1500
        })
      })
    },
    /**
     * 输入框的值
     */
    getInputVal: function (e) {
      const type = e.currentTarget.dataset.type
      if (type == 'account') {
        this.setData({
          principal: e.detail.value
        })
      } else if (type == 'password') {
        this.setData({
          credentials: e.detail.value
        })
      }
    },

    getPassInputVal: function (e) {
      var type = e.currentTarget.dataset.type
      if (type == 0) {
        this.newPassWord = e.detail.value
        // 密码由字母加数字或符号至少两种以上字符组成6-20位半角字符，区分大小写
        var reg = new RegExp('^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z\\W]{6,20}$')
        const result = reg.test(this.newPassWord)
        if (!result) {
          this.setData({
            errorTips: 9
          })
          return
        } else {
          this.setData({
            errorTips: 0
          })
        }
      } else if (type == 1) {
        if (this.errorTips == 9) {
          this.setData({
            errorTips: 10
          })
          return
        }
        this.comNewPassWord = e.detail.value
        setTimeout(() => {
          if (this.errorTips == 9 || this.errorTips == 10) {
            return
          }
          if (this.comNewPassWord && this.newPassWord && (this.comNewPassWord != this
            .newPassWord)) {
            this.setData({
              errorTips: 7,
              identical: false
            })
          } else if (!this.comNewPassWord) {
            this.errorTips = 5
          } else {
            this.setData({
              errorTips: 0,
              identical: true
            })
          }
        }, 1000)
      }
    },

    /**
     * 登录
     */
    login () {
      if (this.principal.length == 0) {
        this.errorTips = 1
        return
      }
      if (this.credentials.length == 0) {
        this.errorTips = 2
        return
      }
      this.errorTips = 0
      if (!this.isPrivacy || this.isPrivacy === -1) {
        this.showPop = true
        return
      }
      const params = {
        url: uni.getStorageSync('tempUidB2c') ? '/tempSocialLogin' : '/login',
        method: 'POST',
        data: {
          userName: this.principal,
          passWord: encrypt(this.credentials),
          tempUid: uni.getStorageSync('tempUidB2c')
        },
        callBack: res => {
          util.loginSuccess(res)
        }
      }
      http.request(params)
    },

    /**
     * 修改密码（登录页修改密码按钮）
     */
    forgotPassword () {
      this.setData({
        isForgetPassword: true,
        principal: '',
        credentials: ''
      })

      uni.setNavigationBarTitle({
        title: this.i18n.changePassword
      })
    },

    /**
     * 获取验证码
     */
    getCode: function (num) {
      if (num && num === this.changePasswordData.principal) {
        this.principal = this.changePasswordData.principal
      }
      if ((!util.checkPhoneNumber(this.principal) && !this.isCancellation) && !util.checkPhoneNumber(this.changePasswordData.principal)) {
        this.setData({
          errorTips: 1
        })
        return
      }
      if (this.hadGotCode && !this.isCancellation) {
        return
      }

      /* 如果注销账号 */
      if (this.isCancellation) {
        this.principal = this.userInfo.userMobile
        var params = {
          url: '/sms/send-logout-code',
          method: 'POST',
          data: {
            mobile: this.principal
          },
          callBack: res => {
            this.hadGotCode = true
            const timeCount = 60
            if (!this.timer) {
              this.count = timeCount
              this.show = false
              this.timer = setInterval(() => {
                if (this.count > 0 && this.count <= timeCount) {
                  this.count--
                } else {
                  clearInterval(this.timer)
                  this.timer = null
                  this.show = true
                  this.hadGotCode = false
                }
              }, 1000)
            }
          }
        }
      } else {
        var params = {
          url: '/sms/sendUpdatePwdCode',
          method: 'POST',
          data: {
            mobile: this.principal
          },
          callBack: res => {
            this.hadGotCode = true
            const timeCount = 60
            if (!this.timer) {
              this.count = timeCount
              this.show = false
              this.timer = setInterval(() => {
                if (this.count > 0 && this.count <= timeCount) {
                  this.count--
                } else {
                  clearInterval(this.timer)
                  this.timer = null
                  this.show = true
                  this.hadGotCode = false
                }
              }, 1000)
            }
          }
        }
      }

      var params = {
        url: '/sms/sendUpdatePwdCode',
        method: 'POST',
        data: {
          mobile: this.principal
        },
        callBack: res => {
          this.hadGotCode = true
          const timeCount = 60
          if (!this.timer) {
            this.count = timeCount
            this.show = false
            this.timer = setInterval(() => {
              if (this.count > 0 && this.count <= timeCount) {
                this.count--
              } else {
                clearInterval(this.timer)
                this.timer = null
                this.show = true
                this.hadGotCode = false
              }
            }, 1000)
          }
        }
      }


      http.request(params)
    },

    /**
     * 校验验证码
     */
    checkValidCode () {
      if (!util.checkPhoneNumber(this.principal) && !this.isCancellation) {
        this.setData({
          errorTips: 1
        })
        return
      }
      if (!this.validCode) { // 请输入验证码
        this.setData({
          errorTips: 3
        })
        return
      }
      if (this.errorTips == 9 || this.errorTips == 10) {
        return
      }
      if (!this.newPassWord && !this.isCancellation) {
        this.setData({
          errorTips: 4
        })
        return
      }
      if (!this.newPassWord.trim() && !this.isCancellation) {
        this.setData({
          errorTips: 10
        })
        return
      }
      if (!this.comNewPassWord && !this.isCancellation) {
        this.setData({
          errorTips: 5
        })
        return
      }
      if (this.comNewPassWord && this.newPassWord && (this.comNewPassWord != this.newPassWord) && !this
        .isCancellation) {
        this.setData({
          errorTips: 7,
          identical: false
        })
        return
      }

      /* 注销账号 */
      // if (this.isCancellation) {
      // 	this.principal = this.userInfo.userMobile
      // }

      // 校验验证码
      var params = {
        url: '/user/checkUpdatePwdSms',
        method: 'put',
        data: {
          mobile: this.principal,
          validCode: this.validCode
        },
        callBack: res => {
          this.setData({
            checkRegisterSmsFlag: res,
            isSuccessCancellation: true,
          })
          if (!this.isCancellation) {
            this.changePassWord()
          } else if (this.isCancellation) {
            this.onConfirmCannellation()
          }
        }
      }
      http.request(params)
    },


    /**
     * 修改密码(确认按钮)
     */
    changePassWord () {
      this.newPassWord = this.changePasswordData.newPassWord
      var params = {
        url: '/user/updatePwd',
        method: 'put',
        data: {
          appType: 4, // 应用类型 1小程序 2微信公众号 3 PC
          checkRegisterSmsFlag: this.checkRegisterSmsFlag, // 校验登陆注册验证码成功的标识
          mobile: this.principal,
          password: encrypt(this.newPassWord),
          validCode: this.validCode,
          validateType: 1 // 验证类型 1验证码验证 2 小程序encryptedData验证 3 密码验证
        },
        callBack: res => {
          uni.showToast({
            title: this.i18n.successfullyModified,
            icon: 'none',
            duration: 1500
          })
          this.principal = ''
          this.changePasswordData.principal = ''
          this.credentials = ''
          setTimeout(() => {
            this.isForgetPassword = false
            uni.removeStorageSync('loginResult')
            uni.removeStorageSync('token')
            uni.removeStorageSync('recentSearch')
            util.removeTabBadge()
            // 重置uuid、uuidSession、sessionTimeStamp、step、flowAnalysisLogDto
            uni.setStorageSync('uuid', util.getUuid())
            uni.setStorageSync('uuidSession', util.getUuid())
            uni.setStorageSync('sessionTimeStamp', new Date().getTime())
            uni.setStorageSync('step', 0)
            uni.setStorageSync('flowAnalysisLogDto', '')

            uni.redirectTo({
              url: '/pages/account-login/account-login'
            })
          }, 1500)
        }
      }
      http.request(params)
    },

    // 返回
    goBack () {
      this.setData({
        isForgetPassword: false,
        principal: null,
        credentials: null
        // 修改密码填充
      })

      uni.setNavigationBarTitle({
        title: this.i18n.userLogin
      })
    },

    /**
     * 去注册
     */
    toRegitser () {
      uni.navigateTo({
        url: '/pages/register/register'
      })
    },

    /**
     * 回到首页
     */
    toIndex () {
      // wx.switchTab({
      // 	url: '/pages/index/index'
      // });
      this.$Router.pushTab('/pages/index/index')
    },
    toService () {
      uni.navigateTo({
        url: "/pages/web-view/web-view?url=https://mall-app.cqone.cn/#/service?head=none"
      })
    },
    toPrivacy () {
      // uni.navigateTo({
      // 	url: "/pages/privacy_page/privacy_page"
      // })
      uni.navigateTo({
        url: "/pages/web-view/web-view?url=https://mall-app.cqone.cn/#/privacy?head=none"
      })
    },

    /* 确认注销账号 */
    onConfirmCannellation () {
      var params = {
        url: `/p/user/${this.userInfo.userId}/apply-cancel-account`,
        method: 'post',
        callBack: res => {
          uni.showToast({
            title: "已申请账号注销,请耐心等待!",
            icon: 'none',
            duration: 1500
          })
          if (this.isSuccessCancellation) { //isSuccessCancellation
            uni.switchTab({
              url: '/pages/index/index'
            })
          }
        }
      }
      http.request(params)
    },
  }
}
</script>

<style scoped lang="scss">
/* #ifndef MP-WEIXIN */
@import "./account-login.css";
@import "./account-login.scss";
/* #endif */
/* #ifdef MP-WEIXIN */
@import "./account-login-mp.scss";
/* #endif */
</style>
